import Vue from 'vue'
import App from './App.vue'
import router,{initDynamicRoutes} from './router'
import store from './store'
import './assets/less/index.less'

Vue.config.productionTip = false

import './utils/directive'
import './utils/filters'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI)

//使用组件
import componentArr from './components/index'
componentArr.forEach(item => {
  Vue.component(item.name,item)
})


// 路由拦截器
initDynamicRoutes()   //刷新初始化动态路由
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next()
  } else {
    const token = sessionStorage.getItem('token')
    if (!token) {
      next('/login')
    } else {
      if(to.path === '/'){
        next('/home')
      }else{
        next()
      }
    }
  }
  // next()
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
